package application;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class ComboBoxDemo extends Application{
	
	private String[] flagTitles = {"Canada", "China", "UK"};


	private ImageView[] flagImage = {
			new ImageView("Canada.jpg"), 
			new ImageView("Flag.png"), 
			new ImageView("UK.jpeg")
			};
	

	
	private String[] flagDescription = new String[3];
	
	private DescriptionPane descriptionPane = new DescriptionPane();
	
	private ComboBox<String> cbo = new ComboBox<>();
			
			
	@Override
	public void start(Stage primaryStage) {

		for (ImageView flag : flagImage) {
			flag.setFitHeight(27.30 * 5);
			flag.setFitWidth(40.96 * 5);
		}
		
	
		flagDescription[0] = "The Canadian national flag...";
		flagDescription[1] = "The Chinese national flag...";
		flagDescription[2] = "The UK's national flag...";
		
		setDisplay(0);
		
		BorderPane pane = new BorderPane();
		
		BorderPane paneForComboBox = new BorderPane();
		paneForComboBox.setLeft(new Label("Select a country:"));
		paneForComboBox.setCenter(cbo);
		pane.setTop(paneForComboBox);
		cbo.setPrefWidth(320);
		cbo.setValue("Canada");
		
		ObservableList<String> items = FXCollections.observableArrayList(flagTitles);
		pane.setCenter(descriptionPane);
		cbo.getItems().addAll(items);
		
		cbo.setOnAction(e -> setDisplay(items.indexOf(cbo.getValue())));
		
		Scene scene = new Scene(pane, 450, 200);
		primaryStage.setTitle("ComboBoxDemo");
		primaryStage.setScene(scene);
		primaryStage.show();
		
	}
	
	public void setDisplay(int index) {
		descriptionPane.setTitle(flagTitles[index]);
		descriptionPane.setImage(flagImage[index]);
		descriptionPane.setDescription(flagDescription[index]);
	}
	
	public static void main(String[] args) {
		Application.launch(args);
	}
}
